package com.yonyou.brigade.third_parties.yihao.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.basic_init.model.BriChannel;
import com.yonyou.brigade.basic_init.service.IBaseDocService;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import com.yonyou.brigade.basic_init.service.IUserCenterService;
import com.yonyou.brigade.order_center.model.ThirdResult;
import com.yonyou.brigade.third_parties.yihao.constants.YihaoConstants;
import com.yonyou.brigade.third_parties.yihao.model.YihaoDept;
import com.yonyou.brigade.third_parties.yihao.model.YihaoUser;
import com.yonyou.brigade.third_parties.yihao.service.ICLYHApplyService;
import com.yonyou.brigade.third_parties.yihao.service.ICLYHPublicService;
import com.yonyou.brigade.third_parties.yihao.util.TravelTypeEmun;
import com.yonyou.brigade.order_center.util.YHUtils;
import com.yonyou.brigade.util.HttpClientUtil;
import com.yonyou.ybzboot.starter.common.exception.BaseException;
import com.yonyou.ybzboot.starter.common.exception.BusinessException;
import com.yonyou.ybzboot.starter.common.util.DateUtils;

import com.yonyou.ybzboot.uc.dto.UcUserDto;
import com.yonyou.ybzboot.starter.common.util.RandomUtil;
import com.yonyou.ybzboot.starter.common.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;


import java.util.Arrays;
import java.util.Map;


/**
 * Created by Administrator on 2018/10/15.
 */
@Service
public class CLYHPublicServiceImpl implements ICLYHPublicService{

    @Value("${yihao.url.ssourl}")
    private String SSO_URL;

//    @Value("${yihao.url.addApprovalurl}")
    private  String addApproval_URL = "";

    @Value("${yihao.url.addUserUrl}")
    private String addUserUrl;

    @Value(("${yihao.url.modifyUserUrl}"))
    private String modifyUserUrl;

    @Value(("${yihao.url.addDeptUrl}"))
    private String addDeptUrl;

    @Value("${yihao.url.modifydeptUrl}")
    private String modifydeptUrl;

    @Value("${yihao.url.quitStaffUrl}")
    private String quitStaffUrl;

    @Value("${yihao.url.enableDeptUrl}")
    private String enableDeptUrl;

    @Value(("${yihao.url.disableDeptUrl}"))
    private String disableDeptUrl;

    @Value("${ybz.baseUrl}")
    private String ybzBaseUrl;

    @Value("${ybz.getMnecode.url}")
    private String getMnecode;

    @Autowired
    private IUserCenterService userCenterService;

    @Autowired
    private IBriChannelService briChannelService;

    @Autowired
    private IBaseDocService baseDocService;

    @Autowired
    private YHUtils yHUtils;

    @Autowired
    @Qualifier("userCenterServiceImpl")
    private IUserCenterService iUserCenterService;

    @Autowired
    @Qualifier("CLYHApplyServiceImpl")
    private ICLYHApplyService clyhApplyService;

    private static Logger logger = LoggerFactory.getLogger(CLYHPublicServiceImpl.class);

    @Override
    public String ssoLogin(String pcode,JSONObject jsonObject,String pcOrH5) {
        StringBuffer urlBuffer = new StringBuffer();
        try {
            String tenant = jsonObject.getString("tenant");
            String appid = jsonObject.getString("appid");
            String requestid = String.valueOf(System.currentTimeMillis());
            String account = pcode;
            String skinid = jsonObject.getString("skinid");
            String access_token = yHUtils.getToken(tenant,requestid,jsonObject);
            if (!StringUtils.isEmpty(access_token)){
                urlBuffer.append(SSO_URL)
                        .append("?").append("token=")
                        .append(access_token)
                        .append("&").append("account=")
                        .append(account)
                        .append("&").append("type=")
                        .append("1")
                        .append("&").append("skinid=")
                        .append(skinid)
                        .append("&").append("appid=")
                        .append(appid);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            throw new BaseException(-100,e.getMessage());
        }
        return urlBuffer.toString();
    }


    @Override
    public JSONObject pushApplayOrder(BriChannel channel, String tenant, String orgpk, JSONObject applyOrderJson, boolean isOpenApi){
        logger.info("调用差旅一号申请单同步接口，原始数据："+applyOrderJson);
        JSONObject result = new JSONObject();
        //TODO 酒店预订日期弹性控制
        //TODO 酒店可预订城市范围
        if(channel==null){
            result.put("code" , 1);
            result.put("information" , "未开通差旅一号商旅服务");
            logger.info("租户："+tenant+"未开通差旅一号");
            return result;
        }
        JSONObject config = JSON.parseObject(channel.getConfig());
        String token = yHUtils.getToken(tenant , "ybz"+ DateUtils.getCurrentDateMinusOneDay("yyyy-MM-dd hh-mm-ss") , config);
        JSONArray data = new JSONArray();
        data.add(this.processApplyData(applyOrderJson, tenant, isOpenApi, channel));
        JSONObject approveJson = new JSONObject();
        approveJson.put("access_token" , token);
        approveJson.put("data" , data);
        String pushApplyStr = JSONObject.toJSONString(approveJson);
        try {
            clyhApplyService.pushApplyVoucherToCLYH(pushApplyStr);
        }catch (BusinessException e){
            result.put("code" , 1);
            result.put("information" , "调用差旅一号接口异常"+e.getDetailMsg());
            result.put("msg", "调用差旅一号接口异常"+e.getDetailMsg());
            return result;
        }
        result.put("code" , 0);
        result.put("information" , "同步成功");
        return result;
    }

    /**
     * 组装申请单同步参数
     * @param applyOrderJson 原始数据
     * @return
     */
    private JSONObject processApplyData(JSONObject applyOrderJson, String tenant, boolean isOpenApi, BriChannel briChannel){
        JSONObject appliedData = new JSONObject();
        JSONObject special = applyOrderJson.getJSONObject("special");
        if(CollectionUtils.isEmpty(special)){
            logger.info("组装差旅一号同步申请单参数special中无数据");
            return appliedData;
        }
        String billnum = applyOrderJson.getString("billNum");
        appliedData.put("applyId" , billnum);
        //applyList 是申请信息列表
        JSONArray applyList = new JSONArray();
        appliedData.put("applyPassState" , 0);
        appliedData.put("applyPurpose" , applyOrderJson.getString("billtypeName"));
        appliedData.put("applyReason" , applyOrderJson.getString("descript"));
        appliedData.put("applyState" , 1);
        List<UcUserDto> ucUserDtos = new ArrayList<>();
        if (isOpenApi) {
            UcUserDto userDto = iUserCenterService.getCompleteUcUserDtoByPhone(applyOrderJson.getString("userId"), tenant);
            if (userDto != null) {
                ucUserDtos.add(userDto);
            }
        } else {
            ucUserDtos = iUserCenterService.getCompleteUcUserDtoByUserid(Arrays.asList(new String[]{applyOrderJson.getString("userId")}), tenant);
        }
        appliedData.put("submitStaff" , CollectionUtils.isEmpty(this.processStaff(applyOrderJson, ucUserDtos, special.getString("openType"), tenant, true)) ? null : this.processStaff(applyOrderJson, ucUserDtos, special.getString("openType"), tenant, true).getJSONObject(0));
        JSONObject applyInfo = new JSONObject();
        //staffList  出行人列表
        JSONArray staffList = this.processStaff(applyOrderJson, ucUserDtos, special.getString("openType"), tenant, false);
        applyInfo.put("staffList" , staffList);
        //voyageList  行程列表
        JSONArray voyageList = this.processVoyage(applyOrderJson);
        applyInfo.put("voyageList" , voyageList);
        applyList.add(applyInfo);
        appliedData.put("applyList" , applyList);
        //组装费用承担信息
        processCostInfo(applyOrderJson, ucUserDtos, appliedData, briChannel, tenant, special.getString("openType"));
        return appliedData;
    }

    private void processCostInfo(JSONObject applyOrderJson, List<UcUserDto> ucUserDtos, JSONObject appliedData, BriChannel briChannel, String tenant, String openType) {
        if (briChannel != null && briChannel.getSyncCostInfo() != 0) {
            //费用承担部门
            String assumeDept = applyOrderJson.getString("assumeDept");
            String[] assumeDeptArr = assumeDept != null ? assumeDept.split(",") : null;
            //费用承担单位
            String assumeOrg = applyOrderJson.getString("assumeOrg");
            String[] assumeOrgArr = assumeOrg != null ? assumeOrg.split(",") : null;
            String assumeDeptCode = "";
            String assumeDeptName = "";
            String assumeOrgCode = "";
            String assumeOrgName = "";
            JSONObject paramJSON = new JSONObject();
            if (CollectionUtils.isEmpty(ucUserDtos)) {
                throw new BusinessException("提单人" + applyOrderJson.getString("userId") + "未同步到用户中心，请检查");
            }
            paramJSON.put("tenantId", tenant);
            paramJSON.put("userId", ucUserDtos.get(0).getUserId());
            if (assumeDeptArr != null && assumeDeptArr.length > 0){
                if (assumeDeptArr.length > 1){
                    assumeDeptCode = assumeDeptArr[0];
                    assumeDeptName = assumeDeptArr[1];
                }else {
                    Map<String, String> deptInfo = baseDocService.getDeptByOsType(tenant, ucUserDtos.get(0).getUserId() ,assumeDeptArr[0], openType);
                    assumeDeptCode = deptInfo != null ? deptInfo.get("pk") : "";
                    assumeDeptName = deptInfo != null ? deptInfo.get("name") : "";
                }
            }
            if (assumeOrgArr != null && assumeOrgArr.length > 0){
                if (assumeOrgArr.length > 1) {
                    assumeOrgCode = assumeOrgArr[0];
                    assumeOrgName = assumeOrgArr[1];
                }else {
                    Map<String, String> orgInfo = baseDocService.getOrgByOsType(tenant, ucUserDtos.get(0).getUserId(), assumeOrgArr[0], openType);
                    assumeOrgCode = orgInfo != null ? orgInfo.get("pk") : "";
                    assumeOrgName = orgInfo != null ? orgInfo.get("name") : "";
                }
            }
            //成本中心及核算主体
            appliedData.put("costCenterNo", StringUtils.isEmpty(assumeDeptCode) ? null : assumeDeptCode);
            appliedData.put("costCenterName", StringUtils.isEmpty(assumeDeptName) ? null : assumeDeptName);
            appliedData.put("settlementEntityCode", StringUtils.isEmpty(assumeOrgCode) ? null : assumeOrgCode);
            appliedData.put("settlementEntityName", StringUtils.isEmpty(assumeOrgName) ? null : assumeOrgName);
        }
    }

    /**
     * 组装申请单同步参数：组装出行人信息
     * @param applyOrderJson 原始数据
     * @param openType nc/ybz
     * @param tenant
     * @param isSubmit true为组装提交人
     * @return
     */
    private JSONArray processStaff(JSONObject applyOrderJson, List<UcUserDto> ucUserDtos, String openType , String tenant , boolean isSubmit){
        JSONArray staffList = new JSONArray();
        // 旧的实际出行人为手输格式，支持格式  张三（17934125896），李四（14536897562）
        String companion = applyOrderJson.getString("companion");
        if (!StringUtils.isEmpty(companion)) {
            companion = convertTraveler(companion);
            if (companion.contains(":")) {
                String[] split = companion.split(",");
                for (String str : split) {
                    String[] strings = str.split(":");
                    //如果手输实际出行人和制单人一致，则忽略
                    if (split.length == 1 && strings[0].equals(ucUserDtos.get(0).getUserName())){
                        continue;
                    }
                    if (strings.length > 1){
                        String phoneNo = strings[1];
                        UcUserDto companionUser = iUserCenterService.getCompleteUcUserDtoByPhone(phoneNo, tenant);
                        if (companionUser != null && !StringUtils.isEmpty(companionUser.getPersonCode())) {
                            JSONObject staff = new JSONObject();
                            staff.put("empID" , companionUser.getPersonCode());
                            staff.put("phoneNo" , companionUser.getPhone());
                            staff.put("staffName" , companionUser.getUserName());
                            staffList.add(staff);
                        } else {
                            String msg = "用户中心未找到或部分未找到实际出行人companion:" + phoneNo;
                            logger.info(msg);
                        }
                    }else {
                        logger.error("差旅壹号实际出行人未传手机号：" + str);
                    }
                }
            }
        }
        //申请单实际出行人字段,如果该字段启用，同步申请单实际出行人员信息以此为准，否则将本人视为实际出行人。
        String passengers = applyOrderJson.getString("actualPedestrian");
        if (!StringUtils.isEmpty(passengers)  &&  !isSubmit) {
            String[] split = passengers.split(";");
            List<String> personIds = new ArrayList<>();
            for (String str : split) {
                if (str.split(",").length > 0) {
                    personIds.add(str.split(",")[0]);
                }
            }
            List<UcUserDto> companionUser = null;
            if ("nc".equals(openType)) {
                companionUser = iUserCenterService.getCompleteUcUserByPersonIds(personIds, tenant);
            } else {
                companionUser = iUserCenterService.getCompleteUcUserDtoByUserid(personIds, tenant);
            }
            if (companionUser != null) {
                for (UcUserDto ucUserDto : companionUser) {
                    JSONObject staff = new JSONObject();
                    staff.put("empID" , ucUserDto.getPersonCode());
                    staff.put("phoneNo" , ucUserDto.getPhone());
                    staff.put("staffName" , ucUserDto.getUserName());
                    staffList.add(staff);
                }
            } else {
                logger.info("用户中心未找到实际出行人:" + personIds.toString());
                //TODO 用户中心未找到人员时同步erp用户，再次查找。
                throw new BusinessException("用户中心未找到部分实际出行人");
            }
        }else {
            JSONObject staff = new JSONObject();
            if(!CollectionUtils.isEmpty(ucUserDtos)) {
                UcUserDto ucUserDto = ucUserDtos.get(0);
                staff.put("empID", ucUserDto.getPersonCode());
                staff.put("phoneNo", ucUserDto.getPhone());
                staff.put("staffName", ucUserDto.getUserName());
                staffList.add(staff);
            }
        }
        return staffList;
    }

    /**
     * 转换companion中的字符
     *
     * @param companion
     * @return
     */
    public static String convertTraveler(String companion) {
        String convertStr = companion;
        if (companion.contains("（")) {
            convertStr = companion.replaceAll("（", ":");
        }
        if (companion.contains("(")) {
            convertStr = convertStr.replaceAll("\\(", ":");
        }
        if (companion.contains("）")) {
            convertStr = convertStr.replaceAll("）", "");
        }
        if (companion.contains(")")) {
            convertStr = convertStr.replaceAll("\\)", "");
        }
        if (companion.contains("，")) {
            convertStr = convertStr.replaceAll("，", ",");
        }
        if (companion.contains("、")) {
            convertStr = convertStr.replaceAll("、", ",");
        }
        return convertStr;
    }
    /**
     * 组装行程明细
     * @param applyOrderJson 原始数据
     * @return
     */
    private JSONArray processVoyage(JSONObject applyOrderJson){
        JSONArray voyageList = new JSONArray();
        JSONArray nodeBusinessTravelList = applyOrderJson.getJSONArray("nodeBusinessTravelList");
        if(!CollectionUtils.isEmpty(nodeBusinessTravelList)){
            for(int i=0;i<nodeBusinessTravelList.size();i++){
                JSONObject voyage = new JSONObject();
                JSONObject nodeBusinessTravel = nodeBusinessTravelList.getJSONObject(i);
                voyage.put("beginDate" , nodeBusinessTravel.getDate("begindate"));
                voyage.put("endDate" , nodeBusinessTravel.getDate("enddate"));
                if(null==nodeBusinessTravel.getDate("enddate")){
                    voyage.put("endDate" , applyOrderJson.getDate("endDate"));
                }
                voyage.put("fromCity" , nodeBusinessTravel.getString("fromCityName"));
                voyage.put("toCity" , nodeBusinessTravel.getString("toCityName"));
                String tripWay = nodeBusinessTravel.getString("tripWay");
                switch (tripWay){
                    case"飞机":
                    case"火车":
                        voyage.put("travelType" , TravelTypeEmun.getIndexByName(tripWay));
                        voyage.put("travelTypeName" , tripWay);
                        break;
                    default:
                        continue;
                }
                switch (nodeBusinessTravel.getString("tripType")){
                    case "OW":
                        voyage.put("voyageType" , 0);
                        voyage.put("voyageTypeName" , "单程");
                        break;
                    case"RT":
                        voyage.put("voyageType" , 1);
                        voyage.put("voyageTypeName" , "往返");
                }
                voyageList.add(voyage);
            }
        }
        return voyageList;
    }

    @Override
    public ThirdResult sysUserToClyh(UcUserDto ucUserDto, List<YihaoUser> userList, String tenant, BriChannel briChannel, String sysType) {
        List<String> msg = new ArrayList<>();
        JSONObject param = new JSONObject();
        String requestid = RandomUtil.createNumberCode(10);
        requestid = requestid + DateUtils.getCurrentDateMinusOneDay("yyyyMMddHHmmss");
        String token = yHUtils.getToken(tenant, requestid, JSONObject.parseObject(briChannel.getConfig()));
        String url = "";
        if(YihaoConstants.SYS_TYPE_ADD.equals(sysType)){
            url = addUserUrl;
        }else if (YihaoConstants.SYS_TYPE_EDIT.equals(sysType)){
            url = modifyUserUrl;
        }else if (YihaoConstants.SYS_TYPE_QUIT.equals(sysType)){
            url = quitStaffUrl;
        }
        JSONArray data = getUserAccountInfo(ucUserDto, userList, briChannel, sysType);
        param.put("access_token", token);
        param.put("data",data);
        param.put("requestid",requestid);
        try {
            logger.info("同步差旅一号用户参数：【" + param.toJSONString() + "】， 同步类型：" + sysType);
            String strResult = HttpClientUtil.doPostJson(url, param.toJSONString());
            logger.info("同步差旅一号用户结果：【" + strResult + "】");
            JSONObject rs = JSONObject.parseObject(strResult);
            return new ThirdResult(rs.getBoolean("successful"), rs.getString("errmsg") );
        }catch (Exception e){
            logger.info("同步差旅一号用户同步异常：【" + e.getMessage() + "】");
            msg.add(param.toJSONString());
            msg.add(e.getMessage());
            return new ThirdResult(false, "同步异常", msg);
        }
    }

    @Override
    public ThirdResult sysDeptToClyh(List<YihaoDept> deptList, String tenant, JSONObject config, String sysType) {
        JSONObject param = new JSONObject();
        List<String> msg = new ArrayList<>();
        String requestid = RandomUtil.createNumberCode(10);
        requestid = requestid + DateUtils.getCurrentDateMinusOneDay("yyyyMMddHHmmss");
        String token = yHUtils.getToken(tenant, requestid, config);
        JSONArray deptArr = new JSONArray();
        if (deptList == null){
            logger.info("同步差旅壹号部门同步：【部门列表为空】");
            msg.add(param.toJSONString());
            msg.add("同步差旅壹号部门同步：【部门列表为空】");
            return new ThirdResult(false, "同步失败", msg);
        }
        deptArr = getDeptArr(deptList, config);
        String url = addDeptUrl;
        if (YihaoConstants.SYS_TYPE_EDIT.equalsIgnoreCase(sysType)){
            url = modifydeptUrl;
        }else if (YihaoConstants.ENABLE_DEPT.equalsIgnoreCase(sysType)){
            deptArr = getEnableDeptArr(deptList, config);
            url = enableDeptUrl;
        }else if (YihaoConstants.DISABLE_DEPT.equalsIgnoreCase(sysType)){
            deptArr = getEnableDeptArr(deptList, config);
            url = disableDeptUrl;
        }
        param.put("access_token", token);
        param.put("data",deptArr);
        param.put("requestid",requestid);
        try {
            logger.info("同步差旅壹号部门参数：【" + param.toJSONString() + "】, 同步类型：" + sysType);
            String strResult = HttpClientUtil.doPostJson(url, param.toJSONString());
            logger.info("同步差旅壹号部门结果：【" + strResult + "】");
            JSONObject rs = JSONObject.parseObject(strResult);
            return new ThirdResult(rs.getBoolean("successful"), rs.getString("errmsg") );
        }catch (Exception e){
            logger.info("同步差旅壹号部门同步异常：【" + e.getMessage() + "】");
            msg.add(param.toJSONString());
            msg.add(e.getMessage());
            return new ThirdResult(false, "同步异常", msg);
        }
    }

    /**
     * 拼装部门信息
     * @param deptList
     * @param config
     * @return
     */
    private JSONArray getDeptArr(List<YihaoDept> deptList, JSONObject config){
        String companyID = config.getString("companyID");
        String companyName = config.getString("CompanyName");
        JSONArray deptArr = new JSONArray();
        for (YihaoDept yihaoDept : deptList) {
            JSONObject yh = new JSONObject();
            yh.put("companyID", companyID);
            yh.put("companyName", companyName);
            yh.put("superDeptNO", yihaoDept.getSuperDept());
            yh.put("deptNO", yihaoDept.getPkDept());
            yh.put("deptName", yihaoDept.getDeptName());
            yh.put("status", 1);
            deptArr.add(yh);
        }
        return deptArr;
    }

    /**
     * 拼装部门信息(启用或禁用)
     * @param deptList
     * @param config
     * @return
     */
    private JSONArray getEnableDeptArr(List<YihaoDept> deptList, JSONObject config){
        String companyID = config.getString("companyID");
        JSONArray dataArr = new JSONArray();
        JSONObject deptJSON = new JSONObject();
        deptJSON.put("companyID", companyID);
        JSONArray deptArray = new JSONArray();
        for (YihaoDept yihaoDept : deptList) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("deptName", yihaoDept.getDeptName());
            jsonObject.put("outDeptNO", yihaoDept.getPkDept());
            deptArray.add(jsonObject);
        }
        deptJSON.put("deptInfoRequestBoList", deptArray);
        dataArr.add(deptJSON);
        return dataArr;
    }

    @Override
    public ThirdResult sysDeptToClyhByOrg(String tenant, String org){
        BriChannel briChannel = briChannelService.getEnableInfoByTenantOrg(tenant, org, "clyh");
        if (briChannel == null){
            return new ThirdResult(false, "未开通差旅一号服务");
        }
        List<YihaoDept> yihaoDepts = new ArrayList<>();
        List<UcUserDto> ucUserDtoList = userCenterService.getUcUserDtoByOrg(tenant, org);
        for (UcUserDto ucUserDto : ucUserDtoList) {
            YihaoDept yihaoDept = new YihaoDept();
            yihaoDept.setSuperDept(ucUserDto.getOrgPk());
            yihaoDept.setPkDept(ucUserDto.getDeptPk());
            yihaoDept.setTenant(tenant);
            yihaoDept.setDeptName(ucUserDto.getDeptName());
            yihaoDepts.add(yihaoDept);
        }
        return sysDeptToClyh(yihaoDepts, tenant, JSONObject.parseObject(briChannel.getConfig()), YihaoConstants.SYS_TYPE_ADD);
    }

    /**
     * 拼装用户信息参数
     * @param userList
     * @return
     */
    private JSONArray getUserAccountInfo(UcUserDto ucUserDto, List<YihaoUser> userList, BriChannel briChannel, String sysType){
        JSONArray accountArr = new JSONArray();
        JSONObject config = JSONObject.parseObject(briChannel.getConfig());
        String companyID = config.getString("companyID");
        String companyName = config.getString("CompanyName");
        String systemID = config.getString("SystemId");
        for (YihaoUser yihaoUser : userList) {
            //所在部门
            JSONArray deptInfoList = new JSONArray();
            JSONObject deptInfo = new JSONObject();
            deptInfo.put("deptName",yihaoUser.getDeptName());
            deptInfo.put("outDeptNO",yihaoUser.getOutDeptNO());
            deptInfoList.add(deptInfo);
            //员工信息
            JSONObject createUserStaffInfo = new JSONObject();
            createUserStaffInfo.put("companyID",companyID);
            createUserStaffInfo.put("companyName",companyName);
            createUserStaffInfo.put("empID",yihaoUser.getEmpID());
            createUserStaffInfo.put("name",yihaoUser.getName());
            createUserStaffInfo.put("phone",yihaoUser.getPhone());
            createUserStaffInfo.put("gender", yihaoUser.getGender());
            //登录凭证
            JSONObject loginVoucherInfo = new JSONObject();
            loginVoucherInfo.put("empID", yihaoUser.getEmpID());
            loginVoucherInfo.put("systemID", systemID);
            JSONObject accountInfo = new JSONObject();
            accountInfo.put("deptInfoList",deptInfoList);
            //职级信息
            if (StringUtil.isNotEmpty(yihaoUser.getPostName()) && BriChannel.SYNCRANK == briChannel.getSyncRank()){
                accountInfo.put("positionName", yihaoUser.getPostName());
            }
            if (YihaoConstants.SYS_TYPE_ADD.equals(sysType)){
                accountInfo.put("createUserStaffInfo",createUserStaffInfo);
                accountInfo.put("loginVoucherInfo",loginVoucherInfo);
            } else if (YihaoConstants.SYS_TYPE_EDIT.equals(sysType)){
                createUserStaffInfo.put("newEmpID", ucUserDto.getPersonCode());
                accountInfo.put("staffInfoTo",createUserStaffInfo);
            } else if (YihaoConstants.SYS_TYPE_QUIT.equals(sysType) || YihaoConstants.SYS_TYPE_DISABLE.equals(sysType)){
                accountInfo.clear();
                accountInfo.put("empID", yihaoUser.getEmpID());
            }
            accountArr.add(accountInfo);
        }
        return accountArr;
    }
}